package com.example.fw;

public class Contact implements Comparable<Contact>
{

	private String firstname;
	private String lastname;
	private String fullname;

	public Contact setFirstname(String firstname)
	{
		this.firstname = firstname;
		return this;
	}

	public Contact setLastname(String lastname)
	{
		this.lastname = lastname;
		return this;
	}

	public Contact setFullName()
	{
		fullname = firstname + " " + lastname;
		return this;
	}

	public String getFirstname()
	{
		return firstname;
	}

	public String getLastname()
	{
		return lastname;
	}

	public String getFullName()
	{
		this.setFullName();
		return fullname;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((firstname == null) ? 0 : firstname.hashCode());
		result = prime * result + ((lastname == null) ? 0 : lastname.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contact other = (Contact) obj;
		if (firstname == null)
		{
			if (other.firstname != null)
				return false;
		}
		else if (!firstname.equals(other.firstname))
			return false;
		if (lastname == null)
		{
			if (other.lastname != null)
				return false;
		}
		else if (!lastname.equals(other.lastname))
			return false;
		return true;
	}

	@Override
	public String toString()
	{
		return "Contact [firstname=" + firstname + ", lastname=" + lastname + "]";
	}

	@Override
	public int compareTo(Contact other)
	{
		return this.getFullName().toLowerCase().compareTo(other.getFullName().toLowerCase());
	}

}
